package ch.usi.inf.pf2.cell;
import java.awt.Color;

import javax.swing.BorderFactory;
import javax.swing.border.EtchedBorder;

import junit.framework.TestCase;
import ch.usi.inf.pf2.cell.Cell;
import ch.usi.inf.pf2.cell.Data;
import ch.usi.inf.pf2.cell.Text;



/**
 * @author Ebrisa Savina Mastrodicasa
 */


/**
 * TestCell class tests that all the methods and constructors
 * in Cell class work as expected.
 */
public class TestCell extends TestCase {
	
	private Data data1;
	private Cell cell1;
	
	
	/**
	 * Set up properly some standard variable for the tests.
	 */
    protected void setUp()
    {
		data1 = new Text("ciao");
		cell1 = new Cell();
	}
	
	
	/**
	 * Check that the setContent() for storing Data and getContent() methods 
	 * work as expected.
	 */
	public void testSetAndGetContent()
	{
		cell1.setContent(data1);
		assertEquals(data1, cell1.getContent());
	}
	
	
	/**
	 * Check that the setContent() for storing String and getContent() methods
	 * work as expected.
	 */
	public void testSetAndGetStringContent()
	{
		cell1.setContent(Data.createData("ciao"));
		assertEquals("ciao", cell1.getContent().toString());
	}

	
	
	/**
	 * Check that the setColor() and getColor() methods
	 * work as expected.
	 */
	public void testSetAndGetColor()
	{
		cell1.setColor(Color.WHITE);
		assertEquals(Color.WHITE, cell1.getColor());
	}
	
	
	
	/**
	 * Check that the setBorderType() and getBorderType() 
	 * methods work as expected.
	 */
	public void testSetAndGetBorderType()
	{
		cell1.setBorderType(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
		assertEquals(BorderFactory.createEtchedBorder(EtchedBorder.RAISED), cell1.getBorderType());
	}
	
	
	/**
	 * Check that the getContent() method called on an empty
	 * cell returns null.
	 */
	public void testGetContentInEmptyCell()
	{
		assertEquals(null, cell1.getContent());
	}
	
	
	/**
	 * Check that the getColor() method called on an empty
	 * cell returns that is is white.
	 */
	public void testGetColorInEmptyCell()
	{
		assertEquals(Color.WHITE, cell1.getColor());
	}
	
	
	/**
	 * Check that the getBorderType() method called on an empty
	 * cell returns none.
	 */
	public void testGetBorderTypeInEmptyCell()
	{
		assertEquals(BorderFactory.createLineBorder(Color.BLACK), cell1.getBorderType());
	}
	
	/**
	 * Check that the getCellLength() method called on an empty
	 * cell returns 8.
	 */
	public void testGetEmptyCellLength()
	{
		assertEquals(8, cell1.getCellLength());
	}
	
	/**
	 * Check that the getCellLength() method called on a
	 * reset cell returns the expected value.
	 */
	public void testGetCellLength()
	{
		cell1.setCellLength(10);
		assertEquals(10, cell1.getCellLength());
	}
	
	
	/**
	 * Check that the cutContentAccordingCellLength() method
	 * works as expected.
	 */
	public void testCutContentAccordingCellLength()
	{
		cell1.setContent("Hello world! I'm fine.");
		assertEquals("Hello wo", cell1.cutContentAccordingCellLength());
		cell1.setContent("Hello!");
		assertEquals("Hello!  ", cell1.cutContentAccordingCellLength());
		cell1.setContent("Hi guys!");
		assertEquals("Hi guys!", cell1.cutContentAccordingCellLength());
	}

	
	

}
